/*
 *  SoundList.h
 *  SoundController0002
 *
 *  Created by jiro on 11/06/16.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#pragma once

#include "Sound.h"
#include "HarmonicSound.h"
#include "HowlSet.h"
#include <vector>
#include <map>
#include <string>

namespace sc {
namespace hs {

	class SoundList
	{
	private:

		typedef std::pair< HarmonicSound, HarmonicSound > TwoSounds;
	
	private:

		std::vector< Sound > sounds;

		bool isDirty;		//	drity flag of adding or deleting sound

		HowlSet howlList;

		//	key:	nearby note on 12 note well temperament
		//	value:	base note number and harmonic multiple nearby key, as type HarmonicSound
		Sound::NearbyWellTemperamentNotes nearbyWellTemeramentNotes;

	public:

		SoundList();

		virtual ~SoundList();

		void push_back( const Sound& sound );

		void clear();

		size_t size() const;
		
		const Sound& operator [] ( size_t index ) const;

		Sound& operator [] ( size_t index );
		
		const Sound& at( size_t index ) const;

		Sound& at( size_t index );

		const HowlSet& GetHowlSet();

		const Sound::NearbyWellTemperamentNotes& GetNearbyWellTemperamentNotes();

		bool FindNoteWhereMidiNumber( sc::Note::MidiNumber number, std::vector< HarmonicSound >& sounds );



		bool FindNotesIncludeHarmonics( double frequency, SoundList& noteList ) const;

		bool FindNotesIncludeHarmonics( double fromFrequency, double toFrequency, SoundList& noteList ) const;

		bool IsExistNotesIncludeHarmonics( double frequency ) const;

		bool IsExistNotesIncludeHarmonics( double fromFrequency, double toFrequency ) const;

		bool IsExistHowlFrequency( double howlFrequency ) const;

		bool FindHowlFrequency( double fromHowlFreqency, double toHowlFrequency, std::vector< double >& howlFrequencies ) const;

		bool FindTwoSoundsGeneratingHowlFreuency( double howlFrequency, Sound::NearbyWellTemperamentNotes& harmonicSounds ) const;

		std::string ToString( int tabCount = 0 ) const;
		
	private:

		void GetAllHarmonicsList( std::vector< std::vector< double > >& harmonicsList ) const;

	};

	typedef SoundList Chord;

}
}
